package com.bz.redis.controller;


import com.bz.pojo.TbUser;
import com.bz.redis.service.SSOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sso/redis")
public class SSOController {

    @Autowired
    private SSOService ssoService;

    /**
     * 将用于缓存到Redis中
     * @param tbUser
     * @param userToken
     */
    @RequestMapping("/insertUser")
    public void insertUser(@RequestBody TbUser tbUser, @RequestParam String userToken){
        ssoService.insertUser(tbUser,userToken);
    }

    /**
     * 用户退出登录
     * @param userToken
     */
    @RequestMapping("/logout")
    public void logout(@RequestParam String userToken){
        ssoService.logout(userToken);
    }

    /**
     * 根据用户token判断用户在redis中是否失效
     * @param userToken
     * @return
     */
    @RequestMapping("/checkUserToken")
    public TbUser checkUserToken(@RequestParam String userToken){
        return ssoService.checkUserToken(userToken);
    }
}
